package com.yanqu.road.server.cmd.grandchild.school;

import com.yanqu.road.pb.grandchild.GrandChildProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.grandson.GrandChildModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

@Cmd(code = GameProtocol.S_ENTER_SCHOOL, desc = "入学请求")
public class EnterSchoolCmd extends AbstractCommand {
    private List<String> childList;
    private int patronsId;
    private int schoolType;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        GrandChildProto.EnterSchoolReqMsg req = GrandChildProto.EnterSchoolReqMsg.parseFrom(packet.getBytes());
        childList = req.getChildIdList();
        patronsId = req.getPatronsId();
        schoolType = req.getSchoolType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(GrandChildModule.class).enterSchool(schoolType, childList, patronsId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            GrandChildProto.EnterSchoolRespMsg.Builder resp = GrandChildProto.EnterSchoolRespMsg.newBuilder();
            resp.setRet(ret);
            player.sendPacket(ClientProtocol.U_ENTER_SCHOOL, resp);
        }
    }
}
